# coding=utf-8
#

from iminer.agent.models import Agent
from iminer.agent.models import AgentHeartbeat


def backend():
    """ """

    with open("hb.csv", "w") as fp:
        for hb in AgentHeartbeat.objects.filter():
            agent = Agent.objects.filter(alias=hb.alias).first()
            cur_line = "%s,%s,%s,%s" % (hb.alias, getattr(agent, "cpu", 0), hb.local_its, hb.local_avg_its)
            fp.write("%s\n" % cur_line)



